<?php

use yii\helpers\Html;
use yii\grid\GridView;

$this->title = Yii::t('app', 'Customers');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="customer-index">

   <div class="box">
        <div class="box-header">
          <?= Html::a(Yii::t('app', 'Create Customer'), ['create'], ['class' => 'btn btn-success']) ?>
        </div>
        <div class="box-body">
            <p>
                 <?php echo $this->render('_search', ['model' => $searchModel]); ?>
            </p>
            <?= GridView::widget([
                'dataProvider' => $dataProvider,
                'layout'  =>  "{items}\n{summary}\n{pager}",
                'columns' => [
                    ['class' => 'yii\grid\SerialColumn'],

                    [
                        'headerOptions' => ['width' => '20%'],
                        'attribute' => 'name',
                        'value' => function ($model) {
                                return $model->name;
                            },
                    ],
                    
                    [
                        'headerOptions' => ['width' => '20%'],
                        'attribute' => 'en_name',
                        'value' => function ($model) {
                                return $model->en_name;
                            },
                    ],

                    [
                        'headerOptions' => ['width' => '20%'],
                        'attribute' => 'address',
                        'value' => function ($model) {
                                return $model->address;
                            },
                    ],

                    [
                        'headerOptions' => ['width' => '20%'],
                        'attribute' => 'en_address',
                        'value' => function ($model) {
                                return $model->en_address;
                            },
                    ],

                    [
                      'attribute' => 'user_id',
                      'headerOptions' => ['width' => '5%'],
                      'value' => function($model){
                            return isset($model->user) ? $model->user->name : '管理员';
                      }
                    ],

                    [
                        'label'=>'联系人信息',
                        'headerOptions' => ['width' => '5%'],
                        'format'=>'raw',
                        'value' => function($model){

                            $url  = sprintf("/customer/contact/index?customer_id=%d", $model->id); //查看
                            $str  = Html::a('查看联系人',$url,['title' =>'查看联系人','class'=>'btn btn-primary btn-xs cs1',]);
                            
                            return $str;
                         }
                    ],

                    [
                        'class' => 'yii\grid\ActionColumn',
                        'headerOptions' => ['width' => '10%'],
                        'header' => '操 作',
                        'template' =>"{view} {update}"
                    ],
                ],
            ]); ?>
        </div>
    </div>
        
</div>
